package com.thoughtworks;

import java.io.IOException;

import static java.lang.System.exit;

public class ChooseAnOption extends BookCheckout {

    public static void action(int choice) throws IOException {
        Books book[] = new Books[5];
        book[0] = new Books("Java Puzzlers", "Joshua Bloch", 2005);
        book[1] = new Books("Python:The Complete Reference", "Martin C. Brown", 2001);
        book[2] = new Books("Two States", "Chetan Bhagat", 2014);
        book[3] = new Books("Success Series","Sachchida Nand Jha",2013);
        book[4] = new Books("Frankenstein","Mary Shelley",1998);
        int flag = 0;
        if(choice<=2) {
            switch (choice) {
                case 1:
                    for (int i = 0; i < book.length; i++) {
                        for (int j = 0; j <= k; j++) {
                            if (book[i].bookName.equals(checkOutArray[j]))
                                flag = 1;
                        }
                        if (flag == 0)
                            Main.displayBooks(book[i]);
                        flag = 0;
                    }
                    break;
                case 2:
                    exit(0);
            }
        }

        else {
           try {
                throw new InvalidChoiceException("Invalid choice..");
            } catch (InvalidChoiceException e) {
                e.printStackTrace();
            }
            Main.menu();
            int newChoice=Main.getChoice();
            action(newChoice);

        }
    }
}
